from gm.api import *
import talib
import numpy as np
import matplotlib.pyplot as plt

set_token("90be3f863b23ab3c1ef68d1f9b8dc06e4bebb30d")

data = history_n(symbol='SZSE.002310',
                 frequency='1d',
                 count=100,
                 end_time='2017-12-31',
                 fields='high,low,close,open,volume',
                 fill_missing='last',
                 adjust=ADJUST_PREV,
                 df=True
                 )
print(data)
close = np.asarray(data['close'].values)
open = np.asarray(data['open'].values)
high = np.asarray(data['high'].values)
low = np.asarray(data['low'].values)
volume = np.asarray(data['volume'].values) + 0.0

adx = talib.ADX(high, low, close)
adx = np.nan_to_num(adx)
adx = adx / np.max(adx)

ad = talib.AD(high, low, close, volume)
ad = np.nan_to_num(ad)
ad = ad / np.max(ad) + 0.0

plt.plot(ad, 'r', adx, 'b')
plt.show()
